package com.shf.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class AppServerListener implements ServletContextListener,HttpSessionListener{
	
	private Log log = LogFactory.getLog(this.getClass());

	/* (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 * 
	 * 停止 服务的时候可以在启做一些操作
	 */
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		
	}
	
	
	/* (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 * 
	 * 启动 服务的时候可以在此初始一些值
	 */
	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		log.warn("启动系统监听器,初始化h2.baseDir!");
		System.out.println(arg0.getServletContext().getRealPath("/WEB-INF/db"));
		System.setProperty("h2.baseDir", arg0.getServletContext().getRealPath("/WEB-INF/db"));
	}

	
	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
	 * 
	 * session创建的时候 调用   典型应用 在用操作员
	 */
	@Override
	public void sessionCreated(HttpSessionEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
	 * 
	 * session 销毁的时候调用
	 */
	@Override
	public void sessionDestroyed(HttpSessionEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
}
